
MD5_CHECKSUM_FILE	= check.md5

# HI3521 don't have slave chip related images
IMAGES_NEED_VERIFY 	= $(OUTPUT_HB_BK)/$(USR_CRAMFS_NAME)
MD5_CMD				= md5sum $(USR_CRAMFS_NAME)
ifeq ($(SLAVE_CHIP), true)
IMAGES_NEED_VERIFY 	+= $(OUTPUT_HB_BK_SLV)/$(SLAVE_UBOOT)		\
					$(OUTPUT_HB_BK_SLV)/$(SLAVE_KERNEL)			\
					$(OUTPUT_HB_BK_SLV)/$(SLAVE_ROOT_FS_IMG)	
MD5_CMD				+= slave/*

# Try pack HI3532 slave root fs
ifeq "$(MAKECMDGOALS)" "pack"
$(OUTPUT_HB_BK_SLV)/$(SLAVE_ROOT_FS_IMG):$(shell find $(SLAVE_OUTPUT_DIR)/root 2>/dev/null)
	$(MAKE) -C $(SLAVE_OUTPUT_DIR) pack
endif
endif

$(OUTPUT_HB_BK)/$(MD5_CHECKSUM_FILE): $(IMAGES_NEED_VERIFY)
	$(PUSHD) $(OUTPUT_HB_BK); \
	$(MD5_CMD) > $(MD5_CHECKSUM_FILE); \
	$(POPD);

usr.hbgk.bin: $(OUTPUT_HB_BK)/$(USR_CRAMFS_NAME) key $(OUTPUT_HB_BK)/$(MD5_CHECKSUM_FILE) $(GUI_LANG_TAR) $(shell find $(CFG_DIR_NAME)/config/etc/ppp 2>/dev/null)
	@$(ECHO) [$@] Changed file:$?
	$(UPGRADE_MAKER) $(UM_ARCHIVE) $(shell basename $(OUTPUT_HB_BK)) $(CFG_DIR_NAME)/config/etc/ppp $(CFG_DIR_NAME)/logo/$(GUI_LANG_TAR_NAME)
	mv $(UPGRADE_MAKER_OUTPUT_NAME) $@

$(OUTPUT_HB_BK)/$(USR_CRAMFS_NAME):$(shell find $(OUTPUT_USR_FS) 2>/dev/null)
	@$(ECHO) [$@] Changed file:$?
	$(MKDIR) -p  $(OUTPUT_HB_BK)/
	$(MK_CRAMFS) $(OUTPUT_USR_FS) $(OUTPUT_HB_BK)/$(USR_CRAMFS_NAME)

################ restore.bin related files #########################
4M-nor.bin: uboot.bin uImage
	dd if=/dev/zero 	of=$@ bs=1024 count=4096
	dd if=uboot.bin		of=$@ bs=1024 count=512  conv=notrunc seek=0
	dd if=uImage		of=$@ bs=1024 count=3584 conv=notrunc seek=512


YAFFS2_PAGE_SIZE	= 1 # Use 2K byte page size
ifeq ($(PLATFORM), HI3535)
YAFFS2_ECC_TYPE		= 2 # 3535 use 4bit ecc
else
ifeq ($(PLATFORM), HI3536)
YAFFS2_ECC_TYPE		= 2 # 3536 use 4bit ecc
else
ifeq ($(PLATFORM), HI3520D_V300)
YAFFS2_ECC_TYPE		= 4 # HI3520D_V300 use 24bit ecc
else
YAFFS2_ECC_TYPE		= 1 # Other use 1bit ecc
endif
endif
endif

usr.hbgk.yaffs2: $(OUTPUT_HB_BK)/$(USR_CRAMFS_NAME) $(HB_BK_DIR_NAME)/$(WEB_CRAMFS_NAME) $(OUTPUT_HB_BK)/$(MD5_CHECKSUM_FILE)
	@$(ECHO) [$@] Changed file:$?
	$(MK_YAFFS2) $(OUTPUT_HB_BK) $@ $(YAFFS2_PAGE_SIZE) $(YAFFS2_ECC_TYPE)

cfg.hbgk.yaffs2: $(CFG_DIR_NAME)/logo/key $(GUI_LANG_TAR) $(shell find $(OUTPUT_CFG) 2>/dev/null)
	@$(ECHO) [$@] Changed file:$?
	$(MK_YAFFS2) $(CFG_DIR_NAME) $@ $(YAFFS2_PAGE_SIZE) $(YAFFS2_ECC_TYPE)

$(HB_BK_DIR_NAME)/$(WEB_CRAMFS_NAME): $(shell find $(OUTPUT_WEB_FS) 2>/dev/null)
	@$(ECHO) [$@] Changed file:$?
	$(MK_CRAMFS) $(OUTPUT_WEB_FS) $@

# vim:noet:sw=4:ts=4

